package cn.tedu.justone.pack01;

/**
 *  死锁测试.  可重入锁  把锁局部 锁该对象
 * @author Kiven
 */
public class ReenTrantDemo {



    public synchronized void sayA(){
        Integer s = 1;
        synchronized (s){
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName());
            System.out.println("A");
            sayB();
        }

    }

    public  void sayB(){
        Integer s = 2;
        synchronized(s){
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName());
            System.out.println("B");
            sayA();
        }
    }

    public static void main(String[] args) {
        ReenTrantDemo reenTrantDemo = new ReenTrantDemo();
        Thread thread = new Thread(){
            @Override
            public void run() {
                reenTrantDemo.sayA();
            }
        };
        thread.setName("我是1");
        Thread thread1 = new Thread(){
            @Override
            public void run() {
                reenTrantDemo.sayB();
            }
        };
        thread1.setName("我是2");
        thread.start();
        thread1.start();

    }


}
